<?php

/**
 * 合并加载JS和附加显示功能
 *
 * @author zyb
 */
class loadTag {

    private $jm;
    private $dir;

    function __construct() {
        $this->jm = new JSMin();
        $this->dir = new Dir();
    }
    //合并js
    public function js($options) {
    	$mpath=WEB_ROOT.'/imgs/';
        $path =$mpath.'runstatic/' . md5($options['href'].ZYB_RELEASE) . '.js';
        $statics_url =$mpath;
        if (!is_file($path)) {
            //静态资源地址
            $files = explode(',', $options['href']);
            $content = '';
            foreach ($files as $val) {
                $val = str_replace('__STATIC__', $statics_url, $val);
                $content.=file_get_contents($val);
            }
            file_put_contents($path, $this->jm->minify($content));
        }
        echo ( '<script type="text/javascript" src="'.C('zyb_static_url'). 'runstatic/' . md5($options['href'].ZYB_RELEASE) . '.js"></script>');
    }
    //合并css
    public function css($options){
    	$path = ZYB_DATA_PATH . 'static/' . md5($options['href'].ZYB_RELEASE) . '.css';
        $statics_url = C('zyb_statics_url') ? C('zyb_statics_url') : './static';
        if (!is_file($path)) {
            //静态资源地址
            $files = explode(',', $options['href']);
            $content = '';
            foreach ($files as $val) {
                $val = str_replace('__STATIC__', $statics_url, $val);
                $content.=file_get_contents($val);
            }
            file_put_contents($path, $this->jm->minify($content));
        }
        echo ( '<link href="'.C('zyb_site_url'). 'data/static/' . md5($options['href'].ZYB_RELEASE) . '.css" rel="stylesheet">');

    }
}